axios.defaults.headers = {
    'Content-type': 'application/json'
}
// axios.defaults.baseURL = 'http://localhost:8080/reserve'
axios.defaults.baseURL = 'http://121.89.172.98:80/reserve'

var app = new Vue({
    el: '#app',
    data: {
        tableData: [],
        listQuery: {
            sortByField: '',
            order: 'desc',
            currentPage: 1,
            pageSize: 10,
            total: 300

        },
        queryParams: {
            userName: '',
            seatName: '',
            beginTime: '',
            endTime: '',
            ip: ''
        },
        exportOptions: {
            userName: '',
            seatName: '',
            beginTime: '',
            endTime: '',
            ip: ''
        },
        loading: false,
        dialogFormVisible: false
    },
    methods: {
        dateFormatter(row, column) {
            // console.log(row[column.property])
            const longTime = row[column.property]
            if (longTime == null)
                return ''
            const date = new Date(longTime)
            const Y = date.getFullYear() + '-'
            const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
            const D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
            const h = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
            const m = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
            const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
            return Y + '-' + M + '-' + D + ' ' + h + ':' + m + ':' + s
        },
        tableSortChange(column) {
            this.listQuery.pageNum = 1
            if (column.order === 'descending') {
                this.listQuery.sortByField = column.prop
                this.listQuery.order = 'desc'
            } else {
                this.listQuery.sortByField = column.prop
                this.listQuery.order = 'asc'
            }
            this.getList()
        },
        getList() {
            this.loading = true
            this.listQuery.queryParams = this.queryParams
            axios.post(`/seatLog/list`, JSON.stringify(this.listQuery))
                .then(res => {
                    this.tableData = res.data.meta.records
                    this.listQuery.total = res.data.meta.total
                    this.loading = false
                    this.$message.success('加载成功')
                })
                .catch(err => {
                    console.log(err)
                    this.$message.error('加载失败')
                    this.loading = false
                })
        },
        handleSizeChange(size) {
            this.listQuery.pageSize = size
            this.getList()
        },
        handleCurrentChange(currentPage) {
            this.listQuery.currentPage = currentPage
            this.getList()
        },
        resetForm() {
            this.$refs.dataFormRef.resetFields()
            this.getList()
        },
        closeExportForm() {
            this.$refs.exportFormRef.resetFields()
            this.dialogFormVisible = false
        },
        exportDownload() {
            let tempUrl = ''
            for (let k in this.exportOptions) {
                let value = this.exportOptions[k]
                if (value !== '')
                    tempUrl += `&${k}=${encodeURIComponent(value)}`
            }
            tempUrl = tempUrl ? tempUrl.substring(1) : ''
            let url = axios.defaults.baseURL + '/seatLog/download?' + tempUrl
            window.open(url)
            this.closeExportForm()
        },
        searchForm() {
            this.getList()
        }
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
        this.getList()
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {
    },
    beforeCreate() {
    }, //生命周期 - 创建之前
    beforeMount() {
    }, //生命周期 - 挂载之前
    beforeUpdate() {
    }, //生命周期 - 更新之前
    updated() {
    }, //生命周期 - 更新之后
    beforeDestroy() {
    }, //生命周期 - 销毁之前
    destroyed() {
    }, //生命周期 - 销毁完成
    activated() {
    }, //如果页面有keep-alive缓存功能，这个函数会触发
})
